home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / jogos / spherical / Code / Game / update.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-07-13  |  11.2 KB  |  331 lines

  1.  
  2. // Copyright (C) 2002 by Luigi Pino.  All Rights Reserved.
  3.  
  4. /***************************************************************************/
  5.  
  6. #include "../library/neurosis.h"
  7. #include "draw.h"
  8. #include "file_io.h"
  9. #include "hiscore.h"
  10. #include "initialize.h"
  11. #include "main.h"
  12. #include "menu_misc.h"
  13. #include "paddle.h"
  14. #include "sphere.h"
  15. #include "update.h"
  16.  
  17. /***************************************************************************/
  18.  
  19. extern Camera_Class                        camera;
  20. extern Light_Values_Struct        light_values;
  21. extern Mouse_Class                        mouse;
  22. extern Object4_Class                    wall_net;
  23. extern Object4_Class                    wall_side;
  24. extern Paddle_Struct                    paddle_object[];
  25. extern Timing_Class                        timing;
  26. extern Values_Struct                    values;
  27.  
  28. extern float3                                    wall_pts[];
  29.  
  30. /***************************************************************************/
  31.  
  32. void Update_Current_Light_Point()
  33.  
  34. {
  35.     float    check_lowest_score = 2000;
  36.     int        check_rotate_value = 0;
  37.     int        x1;
  38.  
  39.     // Get lowest score
  40.     for (x1=Up;x1<=Right;x1=x1+1)
  41.         {
  42.             if (paddle_object[x1].game_over == false)
  43.                 {
  44.                     if (paddle_object[x1].score < check_lowest_score)
  45.                         check_lowest_score = paddle_object[x1].score;
  46.                 }
  47.         }
  48.  
  49.     // Compare to find lowest score player
  50.     for (x1=Up;x1<=Right;x1=x1+1)
  51.         {
  52.             if (paddle_object[x1].game_over == false)
  53.                 {
  54.                     if (paddle_object[x1].score == check_lowest_score)
  55.                         {
  56.                             if (x1 == Right)
  57.                                 check_rotate_value = check_rotate_value + 1;
  58.                             else if (x1 == Up)
  59.                                 check_rotate_value = check_rotate_value + 2;
  60.                             else if (x1 == Left)
  61.                                 check_rotate_value = check_rotate_value + 4;
  62.                             else if (x1 == Down)
  63.                                 check_rotate_value = check_rotate_value + 8;
  64.                         }
  65.                 }
  66.         }
  67.  
  68.     light_values.distance_destination = 90.0f;
  69.  
  70.     if (check_rotate_value == 0)
  71.         light_values.distance_destination = 0.0f;
  72.     else if (check_rotate_value == 1)
  73.         light_values.rotate_destination = 0.0f;
  74.     else if (check_rotate_value == 2)
  75.         light_values.rotate_destination = 90.0f;
  76.     else if (check_rotate_value == 3)
  77.         light_values.rotate_destination = 45.0f;
  78.     else if (check_rotate_value == 4)
  79.         light_values.rotate_destination = 180.0f;
  80.     else if (check_rotate_value == 5)
  81.         light_values.distance_destination = 0.0f;
  82.     else if (check_rotate_value == 6)
  83.         light_values.rotate_destination = 135.0f;
  84.     else if (check_rotate_value == 7)
  85.         {
  86.             light_values.rotate_destination = 90.0f;
  87.             light_values.distance_destination = 50.0f;
  88.         }
  89.     else if (check_rotate_value == 8)
  90.         light_values.rotate_destination = 270.0f;
  91.     else if (check_rotate_value == 9)
  92.         light_values.rotate_destination = 315.0f;
  93.     else if (check_rotate_value == 10)
  94.         light_values.distance_destination = 0.0f;
  95.     else if (check_rotate_value == 11)
  96.         {
  97.             light_values.rotate_destination = 0.0f;
  98.             light_values.distance_destination = 50.0f;
  99.         }
  100.     else if (check_rotate_value == 12)
  101.         light_values.rotate_destination = 225.0f;
  102.     else if (check_rotate_value == 13)
  103.         {
  104.             light_values.rotate_destination = 270.0f;
  105.             light_values.distance_destination = 50.0f;
  106.         }
  107.     else if (check_rotate_value == 14)
  108.         {
  109.             light_values.rotate_destination = 180.0f;
  110.             light_values.distance_destination = 50.0f;
  111.         }
  112.     else if (check_rotate_value == 15)
  113.         light_values.distance_destination = 0.0f;
  114.  
  115.     // Update current position
  116.     if (light_values.distance_current < light_values.distance_destination)
  117.         {
  118.             light_values.distance_current = light_values.distance_current + (10.0f * timing.Get_Scale());
  119.  
  120.             if (light_values.distance_current > light_values.distance_destination)
  121.                 light_values.distance_current = light_values.distance_destination;
  122.         }
  123.     else if (light_values.distance_current > light_values.distance_destination)
  124.         {
  125.             light_values.distance_current = light_values.distance_current - (10.0f * timing.Get_Scale());
  126.  
  127.             if (light_values.distance_current < light_values.distance_destination)
  128.                 light_values.distance_current = light_values.distance_destination;
  129.         }
  130.  
  131.     if (light_values.rotate_current < light_values.rotate_destination)
  132.         {
  133.             if ((light_values.rotate_destination - light_values.rotate_current) > 180)
  134.                 light_values.rotate_current = light_values.rotate_current - (10.0f * timing.Get_Scale());
  135.             else
  136.                 {
  137.                     light_values.rotate_current = light_values.rotate_current + (10.0f * timing.Get_Scale());
  138.  
  139.                     if (light_values.rotate_current > light_values.rotate_destination)
  140.                         light_values.rotate_current = light_values.rotate_destination;
  141.                 }
  142.         }
  143.     else if (light_values.rotate_current > light_values.rotate_destination)
  144.         {
  145.             if ((light_values.rotate_current - light_values.rotate_destination) > 180)
  146.                 light_values.rotate_current = light_values.rotate_current + (10.0f * timing.Get_Scale());
  147.             else
  148.                 {
  149.                     light_values.rotate_current = light_values.rotate_current - (10.0f * timing.Get_Scale());
  150.  
  151.                     if (light_values.rotate_current < light_values.rotate_destination)
  152.                         light_values.rotate_current = light_values.rotate_destination;
  153.                 }
  154.         }
  155.  
  156.     Fix_Angle(&light_values.rotate_current);
  157. }
  158.  
  159. /***************************************************************************/
  160.  
  161. void Update_Mouse()
  162.  
  163. {
  164.     mouse.Get_Info(true);
  165.  
  166.     // Movement left/right
  167.     if (mouse.change.x != 0.0f)
  168.         camera.axis_destination.z = camera.axis_current.z = camera.axis_current.z + (mouse.change.x * 8.0f * timing.Get_Scale());
  169.  
  170.     // Movement up/down
  171.     if (mouse.change.y != 0.0f)
  172.         camera.axis_destination.x = camera.axis_current.x = camera.axis_current.x + (mouse.change.y * 8.0f * timing.Get_Scale());
  173.  
  174.     // Bound up/down mouse movement
  175.     if (camera.axis_current.x < 285.0f)
  176.         camera.axis_current.x = 285.0f;
  177.     else if (camera.axis_current.x > 359.0f)
  178.         camera.axis_current.x = 359.0f;
  179.  
  180.     // Zoom in
  181.     if ((mouse.button[0].x > 0.0f) && (camera.zoom_current < -60.0f))
  182.         {
  183.             camera.zoom_destination = camera.zoom_current = camera.zoom_current + (150.0f * timing.Get_Scale());
  184.  
  185.             if (camera.zoom_current > -60.0f)
  186.                 camera.zoom_destination = camera.zoom_current = -60.0f;
  187.         }
  188.  
  189.     // Zoom out
  190.     if ((mouse.button[1].x > 0.0f) && (camera.zoom_current > -900.0f))
  191.         {
  192.             camera.zoom_destination = camera.zoom_current = camera.zoom_current - (150.0f * timing.Get_Scale());
  193.  
  194.             if (camera.zoom_current < -800.0f)
  195.                 camera.zoom_destination = camera.zoom_current = -800.0f;
  196.         }
  197. }
  198.  
  199. /***************************************************************************/
  200.  
  201. void Update_Nets()
  202.  
  203. {
  204.     // Top net
  205.     if ((paddle_object[Up].game_over == true) && (wall_pts[35].x < -20.0f))
  206.         {
  207.             if (wall_pts[35].y > 185.0f)
  208.                 {
  209.                     wall_pts[35].y = wall_pts[36].y = wall_pts[35].y - (5.0f * timing.Get_Scale());
  210.  
  211.                     if (wall_pts[35].y < 185.0f)
  212.                         wall_pts[35].y = wall_pts[36].y = 185.0f;
  213.                 }
  214.  
  215.             wall_pts[35].x = wall_pts[35].x + (5.0f * timing.Get_Scale());
  216.             wall_pts[36].x = -(wall_pts[35].x);
  217.  
  218.             if (wall_pts[35].x > -20.0f)
  219.                 {
  220.                     wall_pts[35].x = -20.0f;
  221.                     wall_pts[36].x = 20.0f;
  222.                 }
  223.  
  224.             // Wall
  225.             wall_side.Set_Position(31, wall_pts[34].x, wall_pts[34].y, values.wall_height, wall_pts[35].x, wall_pts[35].y,
  226.                 values.wall_height, wall_pts[35].x, wall_pts[35].y, 0.0f, wall_pts[34].x, wall_pts[34].y, 0.0f);
  227.             
  228.             wall_net.Set_Position(2, wall_pts[35].x, wall_pts[35].y, values.wall_height, wall_pts[36].x, wall_pts[36].y,
  229.                 values.wall_height, wall_pts[36].x, wall_pts[36].y, 0.0f, wall_pts[35].x, wall_pts[35].y, 0.0f);
  230.  
  231.             wall_side.Set_Position(32, wall_pts[36].x, wall_pts[36].y, values.wall_height, wall_pts[37].x, wall_pts[37].y,
  232.                 values.wall_height, wall_pts[37].x, wall_pts[37].y, 0.0f, wall_pts[36].x, wall_pts[36].y, 0.0f);
  233.         }
  234.  
  235.     // Bottom net
  236.     if ((paddle_object[Down].game_over == true) && (wall_pts[12].x < -20.0f))
  237.         {
  238.             if (wall_pts[11].y < -185.0f)
  239.                 {
  240.                     wall_pts[11].y = wall_pts[12].y = wall_pts[11].y + (5.0f * timing.Get_Scale());
  241.  
  242.                     if (wall_pts[11].y > -185.0f)
  243.                         wall_pts[11].y = wall_pts[12].y = -185.0f;
  244.                 }
  245.  
  246.             wall_pts[12].x = wall_pts[12].x + (5.0f * timing.Get_Scale());
  247.             wall_pts[11].x = -(wall_pts[12].x);
  248.  
  249.             if (wall_pts[12].x > -20.0f)
  250.                 {
  251.                     wall_pts[12].x = -20.0f;
  252.                     wall_pts[11].x = 20.0f;
  253.                 }
  254.  
  255.             // Wall
  256.             wall_side.Set_Position(9, wall_pts[10].x, wall_pts[10].y, values.wall_height, wall_pts[11].x, wall_pts[11].y,
  257.                 values.wall_height, wall_pts[11].x, wall_pts[11].y, 0.0f, wall_pts[10].x, wall_pts[10].y, 0.0f);
  258.  
  259.             wall_net.Set_Position(0, wall_pts[11].x, wall_pts[11].y, values.wall_height, wall_pts[12].x, wall_pts[12].y,
  260.                 values.wall_height, wall_pts[12].x, wall_pts[12].y, 0.0f, wall_pts[11].x, wall_pts[11].y, 0.0f);
  261.  
  262.             wall_side.Set_Position(10, wall_pts[12].x, wall_pts[12].y, values.wall_height, wall_pts[13].x, wall_pts[13].y,
  263.                 values.wall_height, wall_pts[13].x, wall_pts[13].y, 0.0f, wall_pts[12].x, wall_pts[12].y, 0.0f);
  264.         }
  265.  
  266.     // Right net
  267.     if ((paddle_object[Right].game_over == true) && (wall_pts[48].y < -20.0f))
  268.         {
  269.             if (wall_pts[47].x > 185.0f)
  270.                 {
  271.                     wall_pts[47].x = wall_pts[48].x = wall_pts[47].x - (5.0f * timing.Get_Scale());
  272.  
  273.                     if (wall_pts[47].x < 185.0f)
  274.                         wall_pts[47].x = wall_pts[48].x = 185.0f;
  275.                 }
  276.  
  277.             wall_pts[48].y = wall_pts[48].y + (5.0f * timing.Get_Scale());
  278.             wall_pts[47].y = -(wall_pts[48].y);
  279.  
  280.             if (wall_pts[48].y > -20.0f)
  281.                 {
  282.                     wall_pts[48].y = -20.0f;
  283.                     wall_pts[47].y = 20.0f;
  284.                 }
  285.  
  286.             // Wall
  287.             wall_side.Set_Position(42, wall_pts[46].x, wall_pts[46].y, values.wall_height, wall_pts[47].x, wall_pts[47].y,
  288.                 values.wall_height, wall_pts[47].x, wall_pts[47].y, 0.0f, wall_pts[46].x, wall_pts[46].y, 0.0f);
  289.  
  290.             wall_net.Set_Position(3, wall_pts[47].x, wall_pts[47].y, values.wall_height, wall_pts[48].x, wall_pts[48].y,
  291.                 values.wall_height, wall_pts[48].x, wall_pts[48].y, 0.0f, wall_pts[47].x, wall_pts[47].y, 0.0f);
  292.  
  293.             wall_side.Set_Position(43, wall_pts[48].x, wall_pts[48].y, values.wall_height, wall_pts[49].x, wall_pts[49].y,
  294.                 values.wall_height, wall_pts[49].x, wall_pts[49].y, 0.0f, wall_pts[48].x, wall_pts[48].y, 0.0f);
  295.         }
  296.  
  297.     // Left net
  298.     if ((paddle_object[Left].game_over == true) && (wall_pts[23].y < -20.0f))
  299.         {
  300.             if (wall_pts[23].x < -185.0f)
  301.                 {
  302.                     wall_pts[23].x = wall_pts[24].x = wall_pts[23].x + (5.0f * timing.Get_Scale());
  303.  
  304.                     if (wall_pts[23].x > -185.0f)
  305.                         wall_pts[23].x = wall_pts[24].x = -185.0f;
  306.                 }
  307.  
  308.             wall_pts[23].y = wall_pts[23].y + (5.0f * timing.Get_Scale());
  309.             wall_pts[24].y = -(wall_pts[23].y);
  310.  
  311.             if (wall_pts[23].y > -20.0f)
  312.                 {
  313.                     wall_pts[23].y = -20.0f;
  314.                     wall_pts[24].y = 20.0f;
  315.                 }
  316.  
  317.             // Wall
  318.             wall_side.Set_Position(20, wall_pts[22].x, wall_pts[22].y, values.wall_height, wall_pts[23].x, wall_pts[23].y,
  319.                 values.wall_height, wall_pts[23].x, wall_pts[23].y, 0.0f, wall_pts[22].x, wall_pts[22].y, 0.0f);
  320.  
  321.             wall_net.Set_Position(1, wall_pts[23].x, wall_pts[23].y, values.wall_height, wall_pts[24].x, wall_pts[24].y,
  322.                 values.wall_height, wall_pts[24].x, wall_pts[24].y, 0.0f, wall_pts[23].x, wall_pts[23].y, 0.0f);
  323.  
  324.             wall_side.Set_Position(21, wall_pts[24].x, wall_pts[24].y, values.wall_height, wall_pts[25].x, wall_pts[25].y,
  325.                 values.wall_height, wall_pts[25].x, wall_pts[25].y, 0.0f, wall_pts[24].x, wall_pts[24].y, 0.0f);
  326.         }
  327.  
  328.     Initialize_Ground_Cover();
  329. }
  330.  
  331. /***************************************************************************/